package com.wzy.orderservice.controller;

import com.wzy.orderapi.model.dto.OrderDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class OrderController {

    @Value("${server.port}")
    private String port;

    @GetMapping("getOrderById")
    public OrderDto getOrderById(@RequestParam("orderId") String orderId){
        return orders.get(orderId);
    }

    @PostMapping("saveOrder")
    public OrderDto saveOrder(@RequestBody OrderDto orderDto){
        orderDto.setProductName(orderDto.getProductName() + port);
        return orders.putIfAbsent(orderDto.getId(), orderDto);
    }

    public static final Map<String , OrderDto> orders = new HashMap<>();
}
